from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-20 14:02:20.798798
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 20, Apr, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0218
Nobs: 632.000 HQIC: -49.4093
Log likelihood: 7710.15 FPE: 2.72262e-22
AIC: -49.6553 Det(Omega_mle): 2.36388e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.330071 0.062773 5.258 0.000
L1.Burgenland 0.106132 0.039649 2.677 0.007
L1.Kärnten -0.110559 0.020771 -5.323 0.000
L1.Niederösterreich 0.196625 0.082872 2.373 0.018
L1.Oberösterreich 0.119848 0.081724 1.467 0.143
L1.Salzburg 0.259509 0.042070 6.169 0.000
L1.Steiermark 0.043099 0.055324 0.779 0.436
L1.Tirol 0.105065 0.044808 2.345 0.019
L1.Vorarlberg -0.065195 0.039546 -1.649 0.099
L1.Wien 0.021612 0.072524 0.298 0.766
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.045390 0.134337 0.338 0.735
L1.Burgenland -0.036559 0.084852 -0.431 0.667
L1.Kärnten 0.041693 0.044452 0.938 0.348
L1.Niederösterreich -0.199806 0.177351 -1.127 0.260
L1.Oberösterreich 0.454742 0.174893 2.600 0.009
L1.Salzburg 0.283690 0.090032 3.151 0.002
L1.Steiermark 0.110090 0.118396 0.930 0.352
L1.Tirol 0.307120 0.095892 3.203 0.001
L1.Vorarlberg 0.026861 0.084630 0.317 0.751
L1.Wien -0.024755 0.155205 -0.159 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187649 0.032129 5.840 0.000
L1.Burgenland 0.089555 0.020294 4.413 0.000
L1.Kärnten -0.007723 0.010632 -0.726 0.468
L1.Niederösterreich 0.245309 0.042417 5.783 0.000
L1.Oberösterreich 0.160590 0.041829 3.839 0.000
L1.Salzburg 0.040376 0.021533 1.875 0.061
L1.Steiermark 0.027730 0.028316 0.979 0.327
L1.Tirol 0.084390 0.022934 3.680 0.000
L1.Vorarlberg 0.054679 0.020241 2.701 0.007
L1.Wien 0.118960 0.037120 3.205 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107539 0.032159 3.344 0.001
L1.Burgenland 0.043371 0.020313 2.135 0.033
L1.Kärnten -0.013444 0.010641 -1.263 0.206
L1.Niederösterreich 0.175012 0.042456 4.122 0.000
L1.Oberösterreich 0.333895 0.041868 7.975 0.000
L1.Salzburg 0.101146 0.021553 4.693 0.000
L1.Steiermark 0.112521 0.028343 3.970 0.000
L1.Tirol 0.092080 0.022956 4.011 0.000
L1.Vorarlberg 0.060969 0.020260 3.009 0.003
L1.Wien -0.013879 0.037154 -0.374 0.709
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110083 0.060168 1.830 0.067
L1.Burgenland -0.045422 0.038004 -1.195 0.232
L1.Kärnten -0.045644 0.019910 -2.293 0.022
L1.Niederösterreich 0.138934 0.079433 1.749 0.080
L1.Oberösterreich 0.163854 0.078332 2.092 0.036
L1.Salzburg 0.283682 0.040324 7.035 0.000
L1.Steiermark 0.058101 0.053028 1.096 0.273
L1.Tirol 0.160535 0.042949 3.738 0.000
L1.Vorarlberg 0.098582 0.037905 2.601 0.009
L1.Wien 0.079515 0.069514 1.144 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053076 0.047199 1.125 0.261
L1.Burgenland 0.027261 0.029812 0.914 0.360
L1.Kärnten 0.052846 0.015618 3.384 0.001
L1.Niederösterreich 0.199051 0.062311 3.194 0.001
L1.Oberösterreich 0.331413 0.061448 5.393 0.000
L1.Salzburg 0.037183 0.031632 1.175 0.240
L1.Steiermark 0.009721 0.041598 0.234 0.815
L1.Tirol 0.122608 0.033691 3.639 0.000
L1.Vorarlberg 0.066870 0.029734 2.249 0.025
L1.Wien 0.100753 0.054530 1.848 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169543 0.056703 2.990 0.003
L1.Burgenland 0.005065 0.035816 0.141 0.888
L1.Kärnten -0.065214 0.018763 -3.476 0.001
L1.Niederösterreich -0.101085 0.074860 -1.350 0.177
L1.Oberösterreich 0.206860 0.073822 2.802 0.005
L1.Salzburg 0.055298 0.038003 1.455 0.146
L1.Steiermark 0.241865 0.049975 4.840 0.000
L1.Tirol 0.500600 0.040476 12.368 0.000
L1.Vorarlberg 0.064194 0.035722 1.797 0.072
L1.Wien -0.074638 0.065512 -1.139 0.255
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.144027 0.062787 2.294 0.022
L1.Burgenland -0.000577 0.039658 -0.015 0.988
L1.Kärnten 0.062190 0.020776 2.993 0.003
L1.Niederösterreich 0.171452 0.082891 2.068 0.039
L1.Oberösterreich -0.053359 0.081742 -0.653 0.514
L1.Salzburg 0.207540 0.042080 4.932 0.000
L1.Steiermark 0.140367 0.055336 2.537 0.011
L1.Tirol 0.059050 0.044819 1.318 0.188
L1.Vorarlberg 0.148461 0.039555 3.753 0.000
L1.Wien 0.123046 0.072540 1.696 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375081 0.037065 10.119 0.000
L1.Burgenland -0.002513 0.023412 -0.107 0.915
L1.Kärnten -0.021043 0.012265 -1.716 0.086
L1.Niederösterreich 0.206778 0.048934 4.226 0.000
L1.Oberösterreich 0.230775 0.048255 4.782 0.000
L1.Salzburg 0.038114 0.024841 1.534 0.125
L1.Steiermark -0.011793 0.032667 -0.361 0.718
L1.Tirol 0.090041 0.026458 3.403 0.001
L1.Vorarlberg 0.053466 0.023351 2.290 0.022
L1.Wien 0.043312 0.042823 1.011 0.312
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036632 0.111819 0.174198 0.140494 0.103105 0.082958 0.037575 0.210663
Kärnten 0.036632 1.000000 -0.024538 0.131592 0.050815 0.086486 0.442826 -0.065731 0.089794
Niederösterreich 0.111819 -0.024538 1.000000 0.318755 0.125410 0.278922 0.069529 0.156916 0.294506
Oberösterreich 0.174198 0.131592 0.318755 1.000000 0.217388 0.301646 0.168232 0.140685 0.242247
Salzburg 0.140494 0.050815 0.125410 0.217388 1.000000 0.127329 0.095039 0.107470 0.126413
Steiermark 0.103105 0.086486 0.278922 0.301646 0.127329 1.000000 0.137782 0.111626 0.040291
Tirol 0.082958 0.442826 0.069529 0.168232 0.095039 0.137782 1.000000 0.065378 0.149814
Vorarlberg 0.037575 -0.065731 0.156916 0.140685 0.107470 0.111626 0.065378 1.000000 -0.001548
Wien 0.210663 0.089794 0.294506 0.242247 0.126413 0.040291 0.149814 -0.001548 1.000000